<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查找 HTML 元素</title>
</head>
<body>
<p>使用 document.forms 查找 HTML 元素</p>

<form id="form1" action="../JS教程/2.html">
  First name: <input type="text" name="fname" value="Bill"><br>
  Last name: <input type="text" name="lname" value="Gates"><br><br>
  <input type="submit" value="提交">
</form>

<button onclick="">点击</button>

<p id="demo"></p>

<script>
  function myFunction() {
    var x = document.forms["form1"];
    var text = "";
    var i;
    for (i = 0; i < x.length ;i++) {
      text += x.elements[i].value + "<br>";
    }
    document.getElementById("demo").innerHTML = text;
  }
</script>
</body>
</html>